<template>
	<view class="">
		<view class="flex align-center border-bottom p-2" hover-class="bg-light" @click="open">
			<view class="mr-2">
				<image class="rounded-circle" :src="item.userPic" style="width: 80rpx; height: 80rpx" mode="aspectFill"></image>
			</view>

			<view class="flex-column justify-between flex-4">
				<view class="flex justify-between">
					<text class="font-weight-bolder">{{ item.nikename }}</text>
					<text class="text-dark font-sm">{{ item.time | timeFormat }}</text>
				</view>
				<view class="flex justify-between position-relative">
					<view class="text-dark font-md text-ellipsis" style="width: 500rpx">{{ item.data }}</view>
					<view>
						<u-badge type="error" :count="item.noread"></u-badge>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import $T from '../../common/time.js';
export default {
	props: {
		item: {
			type: Object,
			default: () => {
				return {};
			}
		},
		index: {
			type: Number,
			default: 0
		}
	},
	filters: {
		timeFormat(value) {
			return $T.gettime(value);
		}
	},
	data() {
		return {};
	},
	methods: {
		open() {
			let user = {
				userId: this.item.userId,
				nikename: this.item.nikename,
				userPic: this.item.userPic
			};
			uni.setStorageSync('user', JSON.stringify(user));
			uni.navigateTo({
				url: '/pages/user-chat/user-chat',
				success: () => {
					
					/* {userId: data.fromId,
					nikename: data.fromName,
					userPic: data.userPic,
					time: data.time, //发送时间
					data: data.data,
					unreadNum: 0,
					noread: 0 //未读数} */
					// 读取当前会话
					this.$store.dispatch('readChatMessage', this.item);
				}
			});
		}
	}
};
</script>

<style></style>
